package com.prs.crm.dao.sms.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.context.Constrains;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.sms.SmsSendDao;
import com.prs.crm.domain.sms.SmsSend;

public class SmsSendDaoImpl extends BaseDaoImpl<SmsSend> implements SmsSendDao{

	@SuppressWarnings("unchecked")
	@Override
	public Collection<SmsSend> getSendingSms() {
		 return (Collection<SmsSend>)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
						Criteria criteria = session.createCriteria(SmsSend.class);
						criteria.add(Restrictions.eq("state", Constrains.SMS_SENDING));
						criteria.addOrder(Order.desc("recordTime"));
						return criteria.list();
					}
				});
	}

}
